package profiler;

import java.lang.reflect.Modifier;

import org.objectweb.asm.Opcodes;

public class DefaultFilter implements Filter {

    public boolean includeMethod(String hostClass, int modifiers, String methodName, String descriptor, String genericParameter,
            String[] exceptions) {
        if (methodName.equals("<init>") || methodName.equals("<cinit>")) {
            return false;
        }
        return Modifier.isPublic(modifiers) && !Modifier.isNative(modifiers) && !Modifier.isAbstract(modifiers);
    }

    public boolean instrumentClass(String className, int modifiers) {
        if (className.startsWith("java") || className.startsWith("sun/") || className.startsWith("profiler/")) {
            return false;
        }
        if ((Opcodes.ACC_INTERFACE & modifiers) != 0) {
            return false;
        }
        return (Opcodes.ACC_PUBLIC & modifiers) != 0 && (Opcodes.ACC_SUPER & modifiers) != 0;
    }

}
